var a = getApp();

Component({
    properties: {
        addShow: {
            type: Boolean,
            value: !1
        }
    },
    options: {
        addGlobalClass: !0
    },
    data: {
        strShow: !1,
        provinceData: [],
        cityData: [],
        districtData: [],
        pickerValue: [ 0, 0, 0 ],
        selectAddressData: []
    },
    lifetimes: {
        attached: function() {
            this._initAddressInfo();
        },
        detached: function() {}
    },
    methods: {
        _closeDateLw: function() {
            this.setData({
                addShow: !1
            });
        },
        _initAddressInfo: function() {
            var t = this;
            wx.getStorage({
                key: "provinceData",
                success: function(a) {
                    console.log("地址信息准备就绪"), t._getProvinceData();
                },
                fail: function(e) {
                    console.log("省fail"), a._getNetWork({
                        url: a.getNetAddresss("member.member-address.address"),
                        success: function(a) {
                            var e = a.data, s = e.data.province, d = e.data.city, i = e.data.district;
                            wx.setStorage({
                                key: "provinceData",
                                data: s
                            }), wx.setStorage({
                                key: "cityData",
                                data: d
                            }), wx.setStorage({
                                key: "districtData",
                                data: i
                            }), t._initAddressInfo();
                        },
                        fail: function(a) {},
                        state: !0
                    });
                }
            });
        },
        _getProvinceData: function() {
            var a = this;
            wx.getStorage({
                key: "provinceData",
                success: function(t) {
                    console.log("省读取成功", t.data), a.setData({
                        provinceData: t.data
                    }), a.setData({
                        "selectAddressData[0].name": t.data[a.data.pickerValue[0]].areaname,
                        "selectAddressData[0].id": t.data[a.data.pickerValue[0]].id,
                        "selectAddressData[0].index": a.data.pickerValue[0]
                    }), a._getCityData();
                }
            });
        },
        _getCityData: function() {
            var a = this.data.selectAddressData[0];
            console.log("城市", "_data", a);
            var t = this;
            wx.getStorage({
                key: "cityData",
                success: function(e) {
                    console.log("城市读取成功", e);
                    for (var s = [], d = 0; d < e.data.length; d++) e.data[d].parentid == a.id && s.push(e.data[d]);
                    console.log("城市数据筛选", s), t.setData({
                        cityData: s
                    }), t.setData({
                        "selectAddressData[1].name": s[t.data.pickerValue[1]].areaname,
                        "selectAddressData[1].id": s[t.data.pickerValue[1]].id,
                        "selectAddressData[1].index": t.data.pickerValue[1]
                    }), t._getDistrictData();
                }
            });
        },
        _getDistrictData: function() {
            var a = this.data.selectAddressData[1];
            console.log("地区", "_data", a), console.log(a);
            var t = this;
            wx.getStorage({
                key: "districtData",
                success: function(e) {
                    console.log("地区读取成功");
                    for (var s = [], d = 0; d < e.data.length; d++) e.data[d].parentid == a.id && s.push(e.data[d]);
                    console.log("地区数据筛选", s), t.setData({
                        districtData: s
                    }), console.log("districtData", s), t.setData({
                        "selectAddressData[2].name": s[t.data.pickerValue[2]].areaname,
                        "selectAddressData[2].id": s[t.data.pickerValue[2]].id,
                        "selectAddressData[2].index": t.data.pickerValue[2]
                    }), console.log("over", t.data.selectAddressData);
                }
            });
        },
        bindChange: function(a) {
            var t = a.detail.value;
            this.data.pickerValue[0] != t[0] && (t[1] = 0, t[2] = 0), this.data.pickerValue[1] != t[1] && (t[2] = 0), 
            this.setData({
                "pickerValue[0]": t[0],
                "pickerValue[1]": t[1],
                "pickerValue[2]": t[2]
            }), this._initAddressInfo();
        },
        resultAdd: function() {
            var a = this.data.selectAddressData;
            this.triggerEvent("resultAddress", a);
        }
    }
});